package com.hbmcc.rxjava.chapter02

import com.hbmcc.rxjava.annotation.ClazzInfo
import com.hbmcc.rxjava.annotation.MethodInfo
import com.hbmcc.rxjava.test.TestActivity
import com.hbmcc.rxjava.util.rxLog
import io.reactivex.rxjava3.core.Observable

/**
 * 创建日期：2020/11/2
 * 描述:第二单元的测试
 * 作者:支豪亮
 */
@ClazzInfo(2, 0, "第二章", "RxJava 基础知识")
class Test02Activity : TestActivity() {
    override fun getTestTitle() = listOf(
        "Observable",
        "Hot Observable 和 Cold Observable",
        "Flowable",
        "Single、Completable和Maybe",
        "Subject 和 Processor",
        "小结"
    )

    @MethodInfo(1, 1, "Observable的创建")
    fun observableCreate() {
        Observable.just("hello").subscribe { item -> rxLog(item) }
    }


    @MethodInfo(1, 2, "subscribe(onNext)")
    fun onNext() {
        Observable.just("hello").subscribe { item -> rxLog(item) }
    }

    @MethodInfo(1, 3, "subscribe(onNext,onError))")
    fun onNextErro() {
        Observable.just("hello").subscribe(
            { item -> rxLog("onNext:$item") },
            { throwInfo -> rxLog("onError:$throwInfo") })
    }

    @MethodInfo(1, 4, "subscribe(onNext,onError,onComplete))")
    fun onNextErrorComplete() {
        Observable.just("hello").subscribe(
            { item -> rxLog("onNext:$item") },
            { throwInfo -> rxLog("onError:$throwInfo") },
            { rxLog("Complete") }
        )
    }

    @MethodInfo(1, 5, "do操作符")
    fun doOperate() {
        Observable.just("hello")
            .doOnLifecycle({ item -> rxLog("doOnLifecycle $item") }, { rxLog("doOnLifecycle Action") })
            .doOnSubscribe { item -> rxLog("doOnSubscribe:$item") }
            .doOnEach { item -> rxLog("doOnEach:$item")}
            .doOnNext { item -> rxLog("doOnNext:$item") }
            .doAfterNext { item -> rxLog("doAfterNext:$item") }
            .subscribe({ item -> rxLog("onNext:$item") },
                { throwInfo -> rxLog("onError:$throwInfo") },
                { rxLog("OnComplete") }
            )
    }


}